package cn.itcast.service.impl;

import cn.itcast.dao.OrderDao;
import cn.itcast.dao.SetmealDao;
import cn.itcast.pojo.Setmeal;
import cn.itcast.service.OrderService;
import com.alibaba.dubbo.config.annotation.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(version = "1.0.0")
@Slf4j
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private SetmealDao setmealDao;

    @Override
    public Map<String,Object> queryMealAndCount() {
        //获取所有的套餐对象
        List<Setmeal> list = this.setmealDao.findAll();
        List<String> setmealNames=new ArrayList<>();
        List<Integer> setmealCount=new ArrayList<>();
        for (Setmeal setmeal : list) {
            //取出所有的套餐的名字
            log.info("-------------------所有套餐为:{}",setmeal);
            setmealNames.add(setmeal.getName());
            //根据套餐id查询数据库得到预约的人数
            setmealCount.add( this.orderDao.selectMemberCount(setmeal.getId()));
        }

        Map<String,Object> map=new HashMap<>();
        map.put("setmealNames",setmealNames);
        map.put("setmealCount",setmealCount);
        log.info("返回map集合为:{}",map);
        return map;


    }

    @Override
    public List<Map> findHotSetmeal() {
        return this.orderDao.findHotSetmeal();
    }
}
